package com.xh.audit.controller.project;

import com.xh.audit.entity.project.SolicitOpinions;
import com.xh.audit.service.SolicitOpinionsService;
import com.xh.common.R;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * <p>
 * 审计征求意见/报告 前端控制器
 * </p>
 *
 * @author lhl
 * @since 2023-10-19
 */
@RestController
@RequestMapping("/solicit-opinions")
@RequiredArgsConstructor
@Validated
public class SolicitOpinionsController {

    private final SolicitOpinionsService solicitOpinionsService;

    @PostMapping("/save")
    public R<SolicitOpinions> save(@RequestBody
                                        @Validated
                                               SolicitOpinions tosave) {
        boolean saveFlag = solicitOpinionsService.saveOrUpdate(tosave);
        if (saveFlag) {
            return R.success(solicitOpinionsService.getById(tosave.getId()));
        }
        return R.failed("保存失败");
    }

    @PostMapping("/info/{id}")
    public R<SolicitOpinions> info(@PathVariable
                               @Validated
                               @NotNull(message = "id不能空")
                                       Integer id) {

        SolicitOpinions byId = solicitOpinionsService.getById(id);
        return R.success(byId);
    }

}
